Skip to content

CLN GH22875 Replace bare excepts by explicit excepts in pandas/io/ #23004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 10, 2018

Conversation

JustinZhengBC
Copy link
Contributor

@JustinZhengBC JustinZhengBC commented Oct 5, 2018

This is a resubmit of a previous PR I submitted that was approved (#22916). I tried to close and reopen to get a rebuild on travis but I couldn't reopen it because I had deleted my old fork (after accidentally pushing to master).

@pep8speaks
Copy link

pep8speaks commented Oct 5, 2018

Hello @JustinZhengBC! Thanks for updating the PR.

Comment last updated on October 09, 2018 at 18:52 Hours UTC

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. small comment. ping on green.

try:
return try_read(path)
except:
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment here

@jreback jreback added the Error Reporting Incorrect or improved errors from pandas label Oct 5, 2018
@jreback jreback added this to the 0.24.0 milestone Oct 5, 2018
@codecov
Copy link

codecov bot commented Oct 5, 2018

Codecov Report

Merging #23004 into master will increase coverage by <.01%.
The diff coverage is 36.84%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #23004      +/-   ##
==========================================
+ Coverage   92.19%   92.19%   +<.01%     
==========================================
  Files         169      169              
  Lines       50831    50911      +80     
==========================================
+ Hits        46864    46939      +75     
- Misses       3967     3972       +5
Flag Coverage Δ
#multiple 90.61% <36.84%> (ø) ⬆️
#single 42.3% <5.26%> (-0.05%) ⬇️
Impacted Files Coverage Δ
pandas/io/clipboards.py 100% <ø> (ø) ⬆️
pandas/io/formats/terminal.py 21.25% <0%> (ø) ⬆️
pandas/io/sas/sas_xport.py 90.23% <0%> (ø) ⬆️
pandas/io/sas/sasreader.py 86.2% <0%> (ø) ⬆️
pandas/io/packers.py 88.04% <50%> (ø) ⬆️
pandas/io/parsers.py 95.6% <50%> (ø) ⬆️
pandas/io/formats/console.py 75.75% <75%> (ø) ⬆️
pandas/core/internals/concat.py 98% <0%> (-0.38%) ⬇️
pandas/core/indexes/period.py 93.31% <0%> (-0.35%) ⬇️
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4976ee1...ee85901. Read the comment docs.

@JustinZhengBC
Copy link
Contributor Author

@jreback the tests are green now.

Also, I have another PR with a similar problem (#22904). Is there a way to force travis to rebuild without committing new changes or should I just resubmit the PR?

@jreback
Copy link
Contributor

jreback commented Oct 6, 2018

Also, I have another PR with a similar problem (#22904). Is there a way to force travis to rebuild without committing new changes or should I just resubmit the PR?

you can just push another commit, or generate a new hash
git commit --all --amend -C HEAD

# reg/patched pickle
try:
return read_wrapper(
lambda f: pc.load(f, encoding=encoding, compat=False))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason you elminated this branch here? IIRC this was a perf issue (IOW try the compat=False), but I wrote this code a long time ago.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it appears that since then, someone has modified the load function so that compat isn't used at all.

def load(fh, encoding=None, compat=False, is_verbose=False):
"""load a pickle, with a provided encoding
if compat is True:
fake the old class hierarchy
if it works, then return the new type objects
Parameters
----------
fh: a filelike object
encoding: an optional encoding
compat: provide Series compatibility mode, boolean, default False
is_verbose: show exception output
"""
try:
fh.seek(0)
if encoding is not None:
up = Unpickler(fh, encoding=encoding)
else:
up = Unpickler(fh)
up.is_verbose = is_verbose
return up.load()
except (ValueError, TypeError):
raise

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am skeptical, I put this here because of performance issues. Can you run the asv for the pickle tests? though it might be only a case of reading py2 in py3 which is affected by this, which we prob don't perf check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also see if we actually hit this branch in any tests (meaning the try part is certainly hit, but the except is the question)

# reg/patched pickle
try:
return read_wrapper(
lambda f: pc.load(f, encoding=encoding, compat=False))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am skeptical, I put this here because of performance issues. Can you run the asv for the pickle tests? though it might be only a case of reading py2 in py3 which is affected by this, which we prob don't perf check.

# reg/patched pickle
try:
return read_wrapper(
lambda f: pc.load(f, encoding=encoding, compat=False))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also see if we actually hit this branch in any tests (meaning the try part is certainly hit, but the except is the question)

@JustinZhengBC
Copy link
Contributor Author

Output of benchmark tests:

· Creating environments
· Discovering benchmarks
· Running 4 total benchmarks (2 commits * 1 environments * 2 benchmarks)
[  0.00%] · For pandas commit ee808033 <master> (round 1/2):
[  0.00%] ·· Building for conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt..............................................
[  0.00%] ·· Benchmarking conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt
[ 12.50%] ··· Running (io.pickle.Pickle.time_read_pickle--)..
[ 25.00%] · For pandas commit 6b54cf8b <BUG-22984> (round 1/2):
[ 25.00%] ·· Building for conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt...
[ 25.00%] ·· Benchmarking conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt
[ 37.50%] ··· Running (io.pickle.Pickle.time_read_pickle--)..
[ 50.00%] · For pandas commit 6b54cf8b <BUG-22984> (round 2/2):
[ 50.00%] ·· Benchmarking conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt
[ 62.50%] ··· io.pickle.Pickle.time_read_pickle                         23.0±2ms
[ 75.00%] ··· io.pickle.Pickle.time_write_pickle                        20.9±1ms
[ 75.00%] · For pandas commit ee808033 <master> (round 2/2):
[ 75.00%] ·· Building for conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt...
[ 75.00%] ·· Benchmarking conda-py3.6-Cython-matplotlib-numexpr-numpy-openpyxl-pytables-pytest-scipy-sqlalchemy-xlrd-xlsxwriter-xlwt
[ 87.50%] ··· io.pickle.Pickle.time_read_pickle                         21.9±1ms
[100.00%] ··· io.pickle.Pickle.time_write_pickle                        21.0±1ms

BENCHMARKS NOT SIGNIFICANTLY CHANGED.

Both the remaining except blocks are necessary, as removing them will result in test failures.

Upon further thought, I suppose it could be argued that the branch should remain in case someone modifies the load function later so that compat is used again. Should I put it back?

@jreback
Copy link
Contributor

jreback commented Oct 9, 2018

yeah let's just put it back, but you can add a TODO that should see if can be removed safely., breaking pickle is not great and this is not super well tested.

@jreback
Copy link
Contributor

jreback commented Oct 9, 2018

lgtm. merge on green.

@datapythonista datapythonista merged commit 1a61e26 into pandas-dev:master Oct 10, 2018
@datapythonista
Copy link
Member

Thanks for the fixes @JustinZhengBC, good work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace bare excepts by explicit excepts in pandas/io/
4 participants